package com.twu.module1;

import java.util.ArrayList;

import static com.google.common.collect.Lists.newArrayList;


public class Utilities {

    public static ArrayList<Integer> primeFactors(int n) {
        ArrayList<Integer> factors = getAllFactorsExceptOne(n);
        ArrayList<Integer> result = newArrayList();
        for (Integer factor : factors) {
            if (isPrime(factor)) {
                result.add(factor);
            }
        }
        return result;
    }

    public static boolean isPrime(Integer n) {
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getAllFactorsExceptOne(int n) {
        ArrayList<Integer> factors = newArrayList();
        for (int i = 2; i <= n; i++) {
            if (n % i == 0) {
                factors.add(i);
            }
        }
        return factors;
    }

    public static String lineOfCharacters(int n, String character) {
        String line = "";
        for (int i = 0; i < n; i++) {
            line += character;
        }
        return line;
    }


}
